package com.example.mybaseapp.util

import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.core.content.FileProvider
import java.io.File

class InstallUtil {
     fun install(context: Context,fileString: String){
         val apkFile = File(fileString)

         if (apkFile.exists()) {
             val intent = Intent(Intent.ACTION_VIEW)
             val uri = FileProvider.getUriForFile(context, "${context.packageName}.provider", apkFile)

             intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
             intent.setDataAndType(uri, "application/vnd.android.package-archive")
             intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
             context.startActivity(intent)
         } else {
             // 处理文件不存在的情况
             Log.d("Fire", "install: 安装的时候，提示文件不存在")
         }
     }
}